package com.maikang.exammall.task.async;

import com.maikang.exammall.entity.Commission;
import com.maikang.exammall.repository.CommissionRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Collection;

@Component
@RequiredArgsConstructor
@Log4j2
public class CommissionAsyncTask {
    private final CommissionRepository commissionRepository;

    @Async("threadPoolTaskExecutor")
    public void saveAll(Collection<Commission> entities) {
        if (ObjectUtils.isEmpty(entities)) return;
        try {
            commissionRepository.saveAll(entities);
        } catch (Exception e) {
            log.error("failed to saveAll commissions: {}", entities, e);
        }
    }
}
